using System;
using System.Collections.Generic;
using System.Linq;
using Common;
using ImageProcessing.Common;
using ImageProcessing.Matchers;

namespace ImageProcessing.Engine
{
    public class FoundObject
    {
        public TagInfo TagInfo { get; set; }
        public List<FeaturesFound> FoundFeatures { get; private set; }
        public float Confidence { get; private set; }

        private int? _foundPointsCount;
        public int FoundPointsCount
        {
            get
            {
                if (_foundPointsCount == null)
                    CalcFoundPoints();

                return _foundPointsCount.Value;
            }
        }

        private void CalcFoundPoints()
        {
            _foundPoints = new List<InterestPoint>(FoundFeatures.Select(x => x.ComparisonPoints));
            _foundPointsCount = _foundPoints.Count;
        }

        private List<InterestPoint> _foundPoints;
        public List<InterestPoint> FoundPoints
        {
            get
            {
                if (_foundPoints == null)
                    CalcFoundPoints();

                return _foundPoints;
            }
        }

        public FoundObject(TagInfo tagInfo, List<FeaturesFound> foundFeatures, float confidence)
        {
            TagInfo = tagInfo;
            FoundFeatures = new List<FeaturesFound>(foundFeatures);
            Confidence = confidence;
        }
    }
}